package jp.yvn.game.shooting.element;

import jp.yvn.game.shooting.logic.EnemyBehaviorPattern;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Point;
import android.graphics.PointF;

/**
 * 敵オブジェクト
 * 
 * @author Yvn_pq
 */
public class BaseEnemyEntity {

	public boolean alive = true;

	/** 敵の行動パターン */
	protected EnemyBehaviorPattern mBehaviorPattern;

	/** 弾幕オブジェクトリスト */
	// protected final ArrayList<EnemyBullet> mBulletList = new
	// ArrayList<EnemyBullet>();

	/** 中心座標 */
	protected PointF mCenterPoint = new PointF(0.0f, 0.0f);

	/** 画像幅、高さ */
	protected int mBmpWidth = 0;
	protected int mBmpHeight = 0;
	protected int mBmpHalfWidth = 0;
	protected int mBmpHalfHeight = 0;

	/** 画面幅、高さ */
	protected int mViewWitdth = 0;
	protected int mViewHeight = 0;

	/** Context */
	protected final Context mContext;

	protected Point mViewSize;

	/** 弾幕速度 */
	protected final float BULLET_SPEED = 0.0f;

	/** 弾幕発射用カウント */
	protected int mBulletFireCnt = 0;

	/** 弾幕を発射しているか */
	protected boolean isFire = false;

	protected int mHP = 10;

	protected int halfWidth = 0;
	protected int halfHeight = 0;

	private int mBP = 0;
	private final PointF mStartPoint;
	private final PointF mEndPont;
	private final float mAppearanceTime;

	/**
	 * コンストラクタ
	 * 
	 * @param context
	 * @param initX
	 * @param initRateY
	 * @param stopRateX
	 * @param width
	 * @param height
	 */
	public BaseEnemyEntity(Context context, PointF startPoint, PointF endPoint, float appearanceTime, Point viewSize, int BehaviorPattern) {
		mContext = context;
		mBP = BehaviorPattern;
		mViewWitdth = viewSize.x;
		mViewHeight = viewSize.y;

		mCenterPoint.x = startPoint.x;
		mCenterPoint.y = startPoint.y;

		mStartPoint = startPoint;
		mEndPont = endPoint;
		mAppearanceTime = appearanceTime;
		mViewSize = viewSize;

	}

	public void setBefavior() {
		mBehaviorPattern = new EnemyBehaviorPattern(mStartPoint, mEndPont, mAppearanceTime, mBP);
	}

	/**
	 * 座標を設定します
	 * 
	 * @param initX
	 * @param initRateY
	 */
	public void getNextPoint() {
		mBehaviorPattern.getNextPoint(mCenterPoint, mBP);
	}

	/**
	 * 描画します
	 * 
	 * @param canvas
	 */
	public void draw(Canvas canvas) {
		// 座標更新
		getNextPoint();
	}

	public void draw(Canvas canvas, Bitmap[] img1, Bitmap[] img2) {
		// 座標更新
		getNextPoint();
	}

	public void takeDamage(int d) {
		mHP -= d;
		if (mHP < 1) {
			alive = false;
		}
	}

	public void fireBullet() {

	}

	/**
	 * オブジェクトのX座標が画面の外かどうか
	 * 
	 * @return boolean
	 */
	public boolean isOutsideView() {
		return mCenterPoint.y + mBmpHalfHeight < 0 || mViewHeight < mCenterPoint.y - mBmpHalfHeight || mCenterPoint.x + mBmpHalfWidth < 0 || mViewWitdth < mCenterPoint.x - mBmpHalfWidth;
	}
}
